<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加助手</title>
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/css/uploadifive.css">
    <link type="text/css" rel="stylesheet" href="/js/plugins/layer/laydate/skins/default/laydate.css" id="LayDateSkin">
</head>
<br>
<div class="form-control" style="display: inline-block;height: auto">
    <input type="tel" class="form-control" style="width: 40%;margin-right: 30px;float: left" required="required" id="telphone" placeholder="请输入手机号">
    <button class="btn btn-info" onclick="handleAdd()">添加用户</button>
</div>
</br>
<table class="table table-striped">
    <caption>发布员列表</caption>
    <thead>
    <tr>
        <th>姓名</th>
        <th>手机号</th>
        <th>邮箱</th>
        <th>删除</th>
    </tr>
    </thead>
    <tbody>
    {{range .users}}
    <tr>
        <td>{{.Username}}</td>
        <td>{{.Phone}}</td>
        <td>{{.Email}}</td>
        <td><button class="btn-danger" onclick="handleDelete(this)">删除</button></td>
    </tr>
    {{else}}
    还没有发布员，添加一位吧。
    {{end}}
    </tbody>
</table>

<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/plugins/validate/messages_zh.min.js"></script>
<script>
    function handleDelete(e) {
        var phone = e.parentElement.parentElement.children[1].innerText;
        $.post("/dushu/delassistant",{"phone":phone},function(result){
            if (result.Code==0){
                swal({title: "删除成功!",
                    text: ""},function () {
                    location.reload();
                });
            }else{
                swal("删除失败!", result.Data);
            }
        });
    }
    function handleAdd() {
        var phone=$("#telphone").val();
        if (phone==""){
            swal("手机号不可为空!", "");
            return;
        }
        console.log(phone);
        $.post("/dushu/addassistant",{"phone":phone},function(result){
            if (result.Code==0){
                swal({title: "添加成功!",
                    text: ""},function () {
                    location.reload();
                });
            }else{
                swal("添加失败!", result.Data);
            }
        });
    }
</script>
</body>
</html>